<?php
/**
 * Each engineer has a duty to keep the code elegant
 * Created by wolffy.
 * Author @wolffy<13750088090@sina.cn>
 * Date: 2018/8/11
 * Time: 20:22
 */
namespace App\Http\Controllers\Api\V1_9_3;

use App\Http\Controllers\Controller;
use App\Jobs\TranslateSlug;
use App\Models\CollectMoneyBill;
use App\Models\RepaymentPlan;
use App\Repositories\RepaymentPlanConsumeRepository;
use App\Repositories\RepaymentPlanRepaymentRepository;
use App\Services\LandingRepaymentC\LandingRepaymentCService;
use App\Services\LandingRepaymentE\LandingRepaymentEService;
use App\Services\MessageService;
use App\Services\RepaymentPlanJobsService;
use App\Services\TaobaoArea\Area;
use App\Services\Xinyan\CertificationBankCardMsgAuth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class TestApiVersionController extends Controller
{
    protected $messageService;
    protected $repaymentPlanJobsService;

    public function __construct(MessageService $messageService, RepaymentPlanJobsService $repaymentPlanJobsService)
    {
        $this->messageService = $messageService;
        $this->repaymentPlanJobsService = $repaymentPlanJobsService;
    }
    
    public function testIM(Request $request)
    {
        $name = ' 啊w liu 辉是 ';
//        dump($name);exit;
        $name = preg_replace('# #','', $name);
        dump($name);exit;
//        $data = CollectMoneyBill::get();
//
////        dd($data);
//        foreach ($data as $key=>$value) {
//            $a = $value['collect_money'] - $value['collect_service_charge'];
//            CollectMoneyBill::where('id', $value['id'])->update(['transferred_money' => $a]);
//        }
//        dd(1);
//        dd($data);
//        dd(1);
//        $data = [];
//        for ($i = 1500; $i < 1500; $i ++) {
//            $data[$i]['username'] = invitedEnCode($i);
//            $data[$i]['password'] = md5(invitedEnCode($i));
//        }
//        $data = array_values($data);
//        //注册极光im用户
//        $jMessageService = new JMessageService();
//        $res = $jMessageService->batchRegister($data);
//        dd($res);
//        $JMessageService = new JMessageService();
//        dd($JMessageService->updatePassword('0005', '123456'));
//        $title1 = '还款成功提醒';
//        $content1 = '还款-单聊';
//        $result1 = $this->messageService->sendMessage('personal', '0003', '0001',
//            1, 11, $title1, $content1, '', '');
//        $title2 = '还款成功提醒';
//        $content2 = '还款-公告-聊天室';
        $templateId = $request->template_id;
        $invitedCode = $request->user_name;
        $detailId = empty($request->detail_id) ? 0 : $request->detail_id;
        $result2 = $this->messageService->messageTemplate($templateId, $invitedCode, '6222520717848556', '广发银行',
            100, '李小白', '13750088090', $detailId, '', '');
//        $result2 = $this->messageService->messageTemplate(12, $invitedCode, '6222520717848556', '广发银行',
//            100, '李小白', '13750088090', $detailId, '', '');
//        $result2 = $this->messageService->messageTemplate(2, $invitedCode, '6222520717848556', '广发银行',
//            100, '李小白', '13750088090', $detailId, '', '');
//        $result2 = $this->messageService->messageTemplate(3, $invitedCode, '6222520717848556', '广发银行',
//            100, '李小白', '13750088090', $detailId, '', '');
//        $result2 = $this->messageService->messageTemplate(4, $invitedCode, '6222520717848556', '广发银行',
//            100, '李小白', '13750088090', $detailId, '', '');
//        $result2 = $this->messageService->messageTemplate(5, $invitedCode, '6222520717848556', '广发银行',
//            100, '李小白', '13750088090', $detailId, '', '');
//        $result2 = $this->messageService->messageTemplate(6, $invitedCode, '6222520717848556', '广发银行',
//            100, '李小白', '13750088090', $detailId, '', '');
//        $result2 = $this->messageService->messageTemplate(7, $invitedCode, '6222520717848556', '广发银行',
//            100, '李小白', '13750088090', $detailId, '', '');
//        $result2 = $this->messageService->messageTemplate(8, $invitedCode, '6222520717848556', '广发银行',
//            100, '李小白', '13750088090', $detailId, '', '');
//        $result2 = $this->messageService->messageTemplate(9, $invitedCode, '6222520717848556', '广发银行',
//            100, '李小白', '13750088090', $detailId, '', '');
//        $result2 = $this->messageService->messageTemplate(10, $invitedCode, '6222520717848556', '广发银行',
//            100, '李小白', '13750088090', $detailId, '', '');
//        $result2 = $this->messageService->messageTemplate(11, $invitedCode, '6222520717848556', '广发银行',
//            100, '李小白', '13750088090', $detailId, '', '');
        dd($result2);
    }

    /**
     * [▼
    "transcode" => "015"
    "dsorderid" => "test_123123"
    "returncode" => "0004"
    "errtext" => "商户未注册"
    ]
     * [▼
    "transcode" => "015"
    "merchno" => "lmkj25se267f69f"
    "dsorderid" => "test_123123"
    "sign" => "dc2c14f0b3824d0a92cada935cc93212"
    "returncode" => "0000"
    "errtext" => "提交成功"
    "subMerchantNo" => "200016665496"
    ]
     *
     * [▼
    "transcode" => "015"
    "merchno" => "lmkj25se267f69f"
    "dsorderid" => "test_123123"
    "sign" => "ecd801264cb04cb8ff053312d8f73028"
    "returncode" => "0001"
    "errtext" => "交易失败[null]"
     *
     * [▼
    "transcode" => "015"
    "merchno" => "lmkj25se267f69f"
    "dsorderid" => "test_123123"
    "sign" => "9cf1ff15daa0220ebf711817afa6a46e"
    "returncode" => "0001"
    "errtext" => "校验失败"
    "orderid" => "2018101315040500100123322"
    ]
    ]
     * [▼
    "transcode" => "015"
    "merchno" => "lmkj25se267f69f"
    "dsorderid" => "test_123124"
    "sign" => "591835b9ec88fcc814ac3266481d2d56"
    "returncode" => "0003"
    "errtext" => "提交成功"
    "orderid" => "2018101315080800100123444"
    ]
     *
     * "transcode" => "015"
    "merchno" => "lmkj25se267f69f"
    "dsorderid" => "test_123124"
    "sign" => "591835b9ec88fcc814ac3266481d2d56"
    "returncode" => "0003"
    "errtext" => "提交成功"
    "orderid" => "2018101315080800100123444"
    ]
     *
     * [▼
    "transcode" => "015"
    "merchno" => "lmkj25se267f69f"
    "dsorderid" => "test_123128"
    "sign" => "9d79393c78bcd6e23f21394f928dca90"
    "returncode" => "0000"
    "errtext" => "成功"
    "balanceAmount" => "9.95"
    ]
     * [2018-10-13 16:09:56] local.INFO: consumeNotify:{"sign":"dbed20bd44518a3ec5c17dca929e1716","amount":"10.00","transtype":"85","merchno":"lmkj25se267f69f","status":"00","signType":"MD5","dsorderid":"test_123127","orderid":"2018101315543500100124654","paytime":"20181013155535"}
    [2018-10-13 16:09:56] local.INFO: consumeNotify:{"sign":"ce2c7dcdd689b3865e9e5861983338a8","amount":"10.00","transtype":"85","merchno":"lmkj25se267f69f","status":"01","signType":"MD5","dsorderid":"test_123127","orderid":"2018101315543500100124654","paytime":"20181013155442"}
    repaymentNotify:{"sign":"f6d281cc51f95a3d9942f82e79616d9a","amount":"9.95","transtype":"86","merchno":"lmkj25se267f69f","status":"00","signType":"MD5","dsorderid":"test_123128","orderid":"2018101317104800100127942","paytime":"20181013171048"}
    {
    "transcode": "015",
    "merchno": "lmkj25se267f69f",
    "dsorderid": "AA17870572258612",
    "sign": "a5e91be67f313dd0f8a8c95bdbe7113f",
    "returncode": "0099",
    "errtext": "当前非交易时间"
    }
     */
    public function subMerchantRegisterE()
    {
        $subMerchantNo = '65073888';
        $landingRepaymentCService = new LandingRepaymentCService();
        $res = $landingRepaymentCService->subMerchantBalanceSelect($subMerchantNo);
        dd($res);
//        $landingRepaymentEService = new LandingRepaymentEService();
//        $idCard = '445281198712081251';
//        $cvn2 = '1222';
//        $expireDate = '379';
//        $trueName = '巫鸿洲';
//        $cvn2 = '245';
//        $expireDate = '1021';
//        $bankMobile = '13416163828';
//        $isPhoto = 'noPhoto';
//        $verifyElement = '1234';//12:两要素(银行卡号 + 姓名) 123:三要素(银行卡号 + 姓名 + 身份证号) 1234:四要素(银行卡号 + 姓名 + 身份证号 + 银行卡预留手机号)
//        $industryType = 'A6';//行业类别 A6 安全、工具类产品
//        $productType = 0;
//        $certificationBankCardMsgAuth = new CertificationBankCardMsgAuth();
//        $idHolder = '刘辉武';
//        $idCard = '440582199412023431';
//        $idcardResult = $certificationBankCardMsgAuth->identityIdCard($idCard, $idHolder, $isPhoto, $industryType);
//        dd($idcardResult);
//        $landingRepaymentEService = new LandingRepaymentEService();
        $landingRepaymentEService = new LandingRepaymentEService();
        $orderNo = makeOrderNo();
        $trueName = '吴锦生';
        $mobile = '18588882867';
        $idCard = '445224199606131232';
//        $subMerchantNo = '200016788147';
//        $subMerchantNo = '200016788536';
//        $subMerchantNo = '200016863963';
        $subMerchantNo = '200016864493';
        $amount = round(9.95 * 100, 2);
        $userFee = 0.5;
        $fixAmount = '0';
        $bankCardNo = '6258081667524678';
        $cvn2 = '245';
        $expireDate = '1021';
//        $res = $landingRepaymentEService->subMerchantRegister($orderNo, $trueName, $mobile, $idCard);
//        dd($res);
//        $res = $landingRepaymentEService->subMerchantConsume($orderNo, $subMerchantNo, $amount, $userFee,
//            $fixAmount, $bankCardNo, $trueName, $mobile, $idCard, $cvn2, $expireDate);
//        $res = $landingRepaymentEService->subMerchantRepayment($orderNo, $subMerchantNo, $amount, $fixAmount,
//            $bankCardNo, $mobile);
        $consume = new RepaymentPlanConsumeRepository();
        $consume = $consume->byId(2098)->toArray();
        $idCard = '440184199408293915';
        $cvn2 = '0323';
        $expireDate = '815';
        $trueName = '胡智杰';
        $bankMobile = '13926001684';
        $consume['plan_consume_sn'] = makeOrderNo();
//        dd($consume);
//        dd(round($consume['consume_rate'] * 100, 2));
        $result = $landingRepaymentEService->subMerchantConsume($consume['plan_consume_sn'], $consume['sub_merchant_no'],
            $consume['consume_money'], $consume['consume_rate'], $consume['consume_every_time_price'], $consume['bank_no'],
            $trueName, $bankMobile, $idCard, $cvn2, $expireDate);
        dd($result);


//        $idCard = '445202199304280314';
//        $cvn2 = '0426';
//        $expireDate = '559';
//        $trueName = '杨木森';
//        $bankMobile = '13632401401';

        $idCard = '440583199303203130';
//        $cvn2 = '0426';
//        $expireDate = '559';
        $trueName = '林树钿';
//        $bankMobile = '18820016459';
//
//        $repayment = new RepaymentPlanRepaymentRepository();
//        $repayment = $repayment->byId(927)->toArray();
//        $repayment['repayment_every_time_money'] = '7440.98';
//        $repayment['bank_mobile'] = $bankMobile;
//        $repayment['plan_repayment_sn'] = makeOrderNo();
//        $repaymentPlan = RepaymentPlan::find(287);
////        dd($repaymentPlan);
//        $result = $this->repaymentPlanJobsService->repaymentLargeAmount($repaymentPlan, $repayment);
//        dd($result);
        $res = $landingRepaymentEService->subMerchantBalanceSelect($orderNo, $subMerchantNo);
        dd($res);
    }

    public function number(Request $request)
    {
        $json = '{"transcode":"027","merchno":"lmkj25se267f69f","dsorderid":"1534558824789512964454216","sign":"082fbdebd4e1163555e6835ba05df121","ordersn":"1534558824789512964454216","returncode":"0035","errtext":"\u901a\u9053\u5f02\u5e38,\u8bf7\u91cd\u8bd5\u6216\u8054\u7cfb\u5ba2\u670d"}';
        dd(json_decode($json, true));
        $result = $this->randNumber($request);
        $sum = array_sum($result);
        echo "总：$sum";
        rsort($result);
        dd($result);
    }

    public function randNumber($request)
    {
        $con = $request->con;
        $day = $request->day;
        $avg = round($con/$day);
        $base = isset($request->base) ? $request->base : floor($avg * 0.07);
        $min = $avg - $base;
        if (0 >= $min) {
            $min = 1;
            $max = 1;
        } else {
            $max = $avg + $base;
        }
        dump('base:' . $base); echo "<br>";
        dump('min:' . $min); echo "<br>";
        dump('avg:' . $avg); echo "<br>";
        dump('max:' . $max); echo "<br>";
        $array = [];
        for ($i = 0; $i < $day-1; $i++) {
            $array[$i] =  mt_rand($min, $max);
        }
        $lastNumber = $con - array_sum($array);
        if ($max < $lastNumber || 0 >= $lastNumber) {
            echo 'return';
            return $this->randNumber($request);
        }
        $array = array_merge($array, [$lastNumber]);
//        if (!$this->diffValue($array, $max)) {
//            return $this->randNumber($request);
//        }
        return $array;
    }

//    public function avg($min, $max, $avg)
//    {
//        $num = $this->randomFloat($min,$max);
////        if ($num < $avg) {
////            return $this->avg($min, $max, $avg);
////        }
//        return $num;
//    }

//    public function diffValue($array, $max)
//    {
//        for($i = 1; $i < count($array); $i++){
//            if ($max < $array[$i]) {
//                return false;
//            }
////            $diffValue = $array[$i] - $array[$i - 1];
////            if (150 < abs($diffValue)) {
////                return false;
////            }
//        }
//        return true;
//    }

    //2位小数的随机数
    public function randomFloat($min = 0, $max = 10)
    {
        return mt_rand($min, $max);
        $num = $min + mt_rand() / mt_getrandmax() * ($max - $min);
        return round($num, 2);
    }

    public function receiveAndPaymentSelect()
    {
        //3.1(902)代收付查询接口
        $url = 'http://pay.huanqiuhuiju.com/authsys/api/auth/execute.do';
        $param = [
            'transcode' => '902',
            'version' => '001',
            'ordersn' => 'A821456714614456',
            'merchno' => 'lmkj25se267f69f',
            'dsorderid' => $_GET['dsorderid'],
            'transtype' => '57',
        ];
        // 根据key排序数组
        ksort($param);
        // 转换成字符串 格式为：key=valkey2=val2
        $singleStr = $this->ToUrlParams($param);
        // 加密字符拼接秘钥进行md5加密，得到签名
        $param['sign'] = md5($singleStr . 'p2c4jrh7');
        $client = new \GuzzleHttp\Client(['verify' => false]);
        $response = $client->request('post', $url, ['form_params' => $param]);
        $json = json_decode($response->getBody()->getContents(), true);
        dd($json);

    }

    public function subMerchantRegisterNotify()
    {
        $get = $_GET;
        $post = $_POST;
        Log::info('子商户入网回调get==' . json_encode($get));
        Log::info('子商户入网回调post==' . json_encode($post));
//        echo 'SUCCESS';
    }
    public function subMerchantRegister()
    {
//        file_put_contents('ruwang_get.log',var_export($_GET,true));
//        file_put_contents('ruwang_post.log',var_export($_POST,true));
//        echo 'SUCCESS';die;
        $url = 'http://pay.huanqiuhuiju.com/authsys/api/hc/execute.do';
        if (empty($sub_merchant_no)) {
            $param = [
                'transcode' => '404',
                'version' => '001',
                'ordersn' => 'A821456714614456',
                'merchno' => 'lmkj25se267f69f',
                'dsorderid' => 'A821456714614460',
                'methodname' => 'network',
                'notifyUrl' => 'https://passport.longmaoguanjia.com/subMerchantRegisterNotify',
                'subMer' => [
                    'subMerType' => 3,
                    'legalName' => '刘辉武',//姓名
                    'legalMobile' => '13750088090',//手机号
                    'legalIdNo' => '440582199412023431',//身份证号
                    'legalValidityFlag' => 1,//证件号是否为长期
                    'legalBankCard' => '6258081666513607',//银行卡号
                    'legalBankName' => '广发银行',//银行名称
                    'legalBankCardType' => 'credit',//银行卡类型 debit(借记卡)，credit(贷记卡)
                    'merOpenName' => '刘辉武',//银行卡开卡姓名
                    'minSettleAmout' => '2',//起结金额
                    'companyAddress' => '广东省广州市天河区',//个人住宅地址
                ],
            ];
            // 根据key排序数组
            ksort($param);
            // 转换成字符串 格式为：key=valkey2=val2
            $singleStr = $this->ToUrlParams($param);
            // 加密字符拼接秘钥进行md5加密，得到签名
            $param['sign'] = md5($singleStr . 'p2c4jrh7');
            $client = new \GuzzleHttp\Client(['verify' => false]);
            $response = $client->request('post', $url, ['json' => $param]);
            $json = json_decode($response->getBody()->getContents(), true);
//            array:2 [▼
//  "returncode" => "0001"
//  "errtext" => "交易失败[null]"
//]

//            [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "dsorderid" => "A821456714614456"
//  "sign" => "8221bdbfcd5736768a0b7c6fe5b1a61c"
//  "ordersn" => "A821456714614456"
//  "returncode" => "0001"
//  "message" => "{"code":"ERR3014","message":"入驻失败","requestNo":"45194INTB193281690376859648","remark":"入驻失败:[\"法人证件号码不正确:440582199412023430\",\"个人地址不正确\"]"}"
//]

//            [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "dsorderid" => "A821456714614456"
//  "sign" => "4e791e246ccd3df2f1cb3887c0d711d0"
//  "ordersn" => "A821456714614456"
//  "returncode" => "0007"
//  "errtext" => "订单重复，请更换商户订单号"
//]
//            array:7 [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "dsorderid" => "A821456714614457"
//  "sign" => "48a52f0a5ccc50c8b48df3f9ffd77158"
//  "ordersn" => "A821456714614456"
//  "returncode" => "0001"
//  "message" => "{"code":"ERR3014","message":"入驻失败","requestNo":"45194INTB193284059021963264","remark":"入驻失败:[\"法人绑定银行卡号码不正确\",\"个人地址不正确\"]"}"
//]

//            [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "dsorderid" => "A821456714614459"
//  "sign" => "b5bae6619b4b63bde753d387068ad09c"
//  "ordersn" => "A821456714614456"
//  "returncode" => "0001"
//  "message" => "{"code":"ERR3014","message":"入驻失败","requestNo":"45194INTB193288939614760960","remark":"入驻失败:[\"个人地址不正确\"]"}"
//]

//            [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "dsorderid" => "A821456714614458"
//  "sign" => "4b5e27f0a72461ed0125d57fc6e791cb"
//  "ordersn" => "A821456714614456"
//  "returncode" => "0000"
//  "message" => "{"code":"SUCCESS","message":"成功","requestNo":"45194INTB193289769235509248","subMerNo":"68706638","subMerchantNo":"68706638","remark":"审核通过,"}"
//]

//            [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "dsorderid" => "A821456714614460"
//  "sign" => "643f4db2fa309e07bb7221af6eec8dad"
//  "ordersn" => "A821456714614456"
//  "returncode" => "0001"
//  "message" => "{"code":"FAIL","message":"该身份证号已入驻","subMerNo":"68706638","subMerchantNo":"68706638"}"
//]
            dd($json);
        }
    }

    public function subMerchantRegisterSelect()
    {
//        file_put_contents('ruwang_get.log',var_export($_GET,true));
//        file_put_contents('ruwang_post.log',var_export($_POST,true));
        $url = 'http://pay.huanqiuhuiju.com/authsys/api/hc/execute.do';
        $param = [
            'transcode' => '404',
            'version' => '001',
            'methodname' => 'queryNetwork',
            'idCardNo' => '440582199412023431',//身份证号
            'merchno' => 'lmkj25se267f69f',
        ];
        // 根据key排序数组
        ksort($param);
        // 转换成字符串 格式为：key=valkey2=val2
        $singleStr = $this->ToUrlParams($param);
        // 加密字符拼接秘钥进行md5加密，得到签名
        $param['sign'] = md5($singleStr . 'p2c4jrh7');
        $client = new \GuzzleHttp\Client(['verify' => false]);
        $response = $client->request('post', $url, ['json' => $param]);
        $json = json_decode($response->getBody()->getContents(), true);
        dd($json);

//        [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "dsorderid" => "A821456714614458"
//  "sign" => "0ba1882cd1fbe1bdb7f10b7fb6f338da"
//  "ordersn" => "A821456714614456"
//  "returncode" => "0000"
//  "message" => "{"code":"SUCCESS","message":"入驻成功","subMerNo":"68706638","subMerchantNo":"68706638"}"
//]
//        [▼
//  "returncode" => "0027"
//  "errtext" => "交易码或请求地址错误"
//]

//        [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "sign" => "35bceb55b109c2386abe63c4ef17ece2"
//  "returncode" => "0000"
//  "message" => "{"code":"SUCCESS","message":"入驻成功","subMerNo":"68706638","subMerchantNo":"68706638"}"
//]
    }

    public function subMerchantBalanceSelect()
    {
//        file_put_contents('ruwang_get.log',var_export($_GET,true));
//        file_put_contents('ruwang_post.log',var_export($_POST,true));
        $url = 'http://pay.huanqiuhuiju.com/authsys/api/hc/execute.do';
        $param = [
            'transcode' => '404',
            'version' => '001',
            'merchno' => 'lmkj25se267f69f',
            'methodname' => 'queryBalance',
            'subMerchantNo' => '36853820',//子商户  //21754813
        ];
//	"dsorderid": "1529686134586",
//	"ordersn": "3a0f4eb96f894350acafc32d1920a491",
//	"orderid": "20180623004854",
//	"": "66006312"
        // 根据key排序数组
        ksort($param);
        // 转换成字符串 格式为：key=valkey2=val2
        $singleStr = $this->ToUrlParams($param);
        // 加密字符拼接秘钥进行md5加密，得到签名
        $param['sign'] = md5($singleStr . 'p2c4jrh7');
        $client = new \GuzzleHttp\Client(['verify' => false]);
        $response = $client->request('post', $url, ['json' => $param]);
        $json = json_decode($response->getBody()->getContents(), true);
        dd($json);
//        [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "sign" => "bc01af6ee2216cf8254c913a5928b3e1"
//  "returncode" => "0000"
//  "message" => "{"amount":"0.00","code":"SUCCESS","message":"请求成功"}"
//]

//        [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "sign" => "0af1434d0d6c9acd7fbd1893aa69568a"
//  "returncode" => "0000"
//  "message" => "{"amount":"2507.65","code":"SUCCESS","message":"请求成功"}"
//]
    }

    public function aa()
    {
      echo '开完卡，回来这里了';
    }

    public function subMerchantOpenCard()
    {
        $url = 'http://pay.huanqiuhuiju.com/authsys/api/hc/execute.do';
        $param = [
            'transcode' => '404',
            'version' => '001',
            'merchno' => 'lmkj25se267f69f',
            'methodname' => 'openCard',
            'subMerchantNo' => '68706638',//子商户  //21754813
            'dsorderid' => 'A821456714614490',
            'mobile' => '13750088090',
            'idCardNo' => '440582199412023431',
            'bankCardNo' => '6258081666513607',
            'cardType' => 'credit',
            'name' => '刘辉武',
            'returnUrl' => 'https://passport.longmaoguanjia.com/subMerchantOpenCardReturn',
            'notifyUrl' => 'https://passport.longmaoguanjia.com/subMerchantRegisterNotify',
        ];
//        [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "dsorderid" => "A821456714614489"
//  "sign" => "80c253a9207eabb20ea4893992551a66"
//  "returncode" => "0000"
//  "message" => "http://pay.huanqiuhuiju.com/authsys/api/html/get.do?fileName=hc2018082216561700100113339&merchNo=lmkj25se267f69f&sign=5977d829eff9b6ed993fa7a393676f38"
//]
        // 根据key排序数组
        ksort($param);
        // 转换成字符串 格式为：key=valkey2=val2
        $singleStr = $this->ToUrlParams($param);
        // 加密字符拼接秘钥进行md5加密，得到签名
        $param['sign'] = md5($singleStr . 'p2c4jrh7');
        $client = new \GuzzleHttp\Client(['verify' => false]);
        $response = $client->request('post', $url, ['json' => $param]);
        $json = json_decode($response->getBody()->getContents(), true);
        dd($json);
    }

    public function subMerchantRepayment()
    {
        $url = 'http://pay.huanqiuhuiju.com/authsys/api/hc/execute.do';
        $param = [
            'transcode' => '404',
            'version' => '001',
            'merchno' => 'lmkj25se267f69f',
            'methodname' => 'trade',
            'subMerchantNo' => '36853820',//子商户  //21754813
            'dsorderid' => 'A821456714614503',
            'bankCardNo' => '6225768649617527',
            'amount' => '43',
            'userFee' => '0.41',
            'mcc' => '5921',
            'notifyUrl' => 'https://passport.longmaoguanjia.com/subMerchantRegisterNotify',
        ];
        // 根据key排序数组
        ksort($param);
        // 转换成字符串 格式为：key=valkey2=val2
        $singleStr = $this->ToUrlParams($param);
        // 加密字符拼接秘钥进行md5加密，得到签名
        $param['sign'] = md5($singleStr . 'p2c4jrh7');
        $client = new \GuzzleHttp\Client(['verify' => false]);
        $response = $client->request('post', $url, ['json' => $param]);
        $json = json_decode($response->getBody()->getContents(), true);
        dd($json);
//        [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "dsorderid" => "A821456714614501"
//  "sign" => "db4ff337cc9f97db15500e45d5a72c4e"
//  "returncode" => "0001"
//  "errtext" => "userFee小于或等于客户端协定费率"
//]
//        [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "dsorderid" => "A821456714614501"
//  "sign" => "5bc17bc2c1115ba4d64b20404611eb34"
//  "returncode" => "0003"
//  "message" => "{"merchantOrderNo":"hc2018082218045100100115666","subMerchantNo":"36853820","amount":"88","userFee":"0.41","cardNo":"6225768649617527","code":"SUCCESS","message ▶"
//]
    }

    public function subMerchantSelect()
    {
        //废弃
        $url = 'http://pay.huanqiuhuiju.com/authsys/api/hc/execute.do';
        $param = [
            'transcode' => '404',
            'version' => '001',
            'merchno' => 'lmkj25se267f69f',
            'methodname' => 'queryTrade',
//            'subMerchantNo' => '36853820',//子商户  //21754813
            'dsorderid' => 'A821456714614501',
        ];
        // 根据key排序数组
        ksort($param);
        // 转换成字符串 格式为：key=valkey2=val2
        $singleStr = $this->ToUrlParams($param);
        // 加密字符拼接秘钥进行md5加密，得到签名
        $param['sign'] = md5($singleStr . 'p2c4jrh7');
        dd(json_encode($param));
        $client = new \GuzzleHttp\Client(['verify' => false]);
        $response = $client->request('post', $url, ['json' => $param]);
        $json = json_decode($response->getBody()->getContents(), true);
        dd($json);
    }

    public function tixian()
    {
        $url = 'http://pay.huanqiuhuiju.com/authsys/api/hc/execute.do';
        $param = [
            'transcode' => '404',
            'version' => '001',
            'merchno' => 'lmkj25se267f69f',
            'methodname' => 'withdraw',
            'subMerchantNo' => '36853820',//子商户  //21754813
            'dsorderid' => 'A821456714614503',
            'bankCardNo' => '6225768649617527',
            'amount' => '33',
//            'userFee' => '0.41',
            'notifyUrl' => 'https://passport.longmaoguanjia.com/subMerchantRegisterNotify',
        ];

        // 根据key排序数组
        ksort($param);
        // 转换成字符串 格式为：key=valkey2=val2
        $singleStr = $this->ToUrlParams($param);
        // 加密字符拼接秘钥进行md5加密，得到签名
        $param['sign'] = md5($singleStr . 'p2c4jrh7');
        $client = new \GuzzleHttp\Client(['verify' => false]);
        $response = $client->request('post', $url, ['json' => $param]);
        $json = json_decode($response->getBody()->getContents(), true);
        dd($json);

//        [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "dsorderid" => "A821456714614501"
//  "sign" => "a43660763b817d4b6920c45129a45936"
//  "returncode" => "0003"
//  "message" => "{"merchantFee":"0.50","code":"SUCCESS","message":"成功"}"
//]

//        [▼
//  "transcode" => "404"
//  "merchno" => "lmkj25se267f69f"
//  "dsorderid" => "A821456714614502"
//  "sign" => "0bc4b6e3bc6027e729831fe795b24323"
//  "returncode" => "0001"
//  "errtext" => "子商户余额不足"
//  "message" => "{"merchantFee":"0.50","code":"FAIL","message":"子商户余额不足"}"
//]
    }

    public function withdraw(LandingRepaymentCService $landingRepaymentCService)
    {

        $orderNo = 'A821456714614505';
        $subMerchantNo = '36853820';
        $bankCardNo = '6225768649617527';
        $amount = 41;
        $userFee = '0.5';
        $result = $landingRepaymentCService->subMerchantRepaymentWithDraw($orderNo, $subMerchantNo, $bankCardNo, $amount, $userFee);
        dd($result);
    }

    public function consume(LandingRepaymentCService $landingRepaymentCService)
    {
        $orderNo = 'A821456714614514';
        $subMerchantNo = '36853820';
        $bankCardNo = '6225768649617527';
        $amount = '24';
        $userFee = '0.411';
        $mcc = '5921';
        $result = $landingRepaymentCService->subMerchantConsume($orderNo, $subMerchantNo, $bankCardNo, $amount, $userFee, $mcc);
        dd($result);
    }

    public function sle(LandingRepaymentCService $landingRepaymentCService)
    {
        $subMerchantNo = '36853820';
        $result = $landingRepaymentCService->subMerchantBalanceSelect($subMerchantNo);
        dd($result);
    }

    // 格式化参数
    public function ToUrlParams($param){
        $string = '';
        foreach ($param as $k=>$v){
            if(is_array($v)){
                $s = '';
                foreach ($v as $key=>$val){
                    $s .= $key.'=' . $val . ', ';
                }
                $s = substr($s,0,-2);
                $string .= $k . '=' . '{'. $s .'}';
            }else{
                $string .= $k . '=' . $v;
            }
        }
        return $string;
    }

    public function jobs()
    {
        $job = (new TranslateSlug())->delay(1);
        dispatch($job);
    }

    public function makeArea()
    {
        $c=new Area();
        $c->getTmpPath('uploads/');
        $c->setUrl();
        $c->setIsCountry(true);
        $c->setMakeCsv(true);

        $c->setExtData();
        $c->process();
    }
}